import { loginIn } from './api/login';

import { register } from './api/register';

import { getCookie } from '../tools/util'

function initEvent(){
    $('#for-login').click(function(){
        $('#for-register').removeClass('active');
        $('#for-login').addClass('active');
        $('#register-form').addClass('hide');
        $('#login-from').removeClass('hide');
    });

    $('#for-register').click(function(){
        $('#for-login').removeClass('active');
        $('#for-register').addClass('active');
        $('#login-from').addClass('hide');
        $('#register-form').removeClass('hide');
    });

    $('#login-account').keydown(function(){
        $('#login-error').hide();
    });

    $('#login-password').keydown(function(){
        $('#login-error').hide();
    });

    $('#register-name').keydown(function(){
        $('#register-error').hide();
    });

    $('#register-account').keydown(function(){
        $('#register-error').hide();
    });

    $('#register-password').keydown(function(){
        $('#register-error').hide();
    });

    $('#login').click(function(){
        loginIn()
    });

    $('#register').click(function(){
        register();
    })
}

function initLogin(){
    var u_name = getCookie('u_name');
    var u_pw = getCookie('u_pw');
    if(u_name && u_pw && u_pw != 'undefined' && u_name != 'undefined'){
        window.location = '/book';
    }
}

$(document).ready(function(){
    initEvent();
    initLogin();
});